package net.huashitong.Indicators.service;

import com.sirdc.modules.utils.NumberUtils;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.Indicators.dataBean.IndexDataDTO;
import net.huashitong.Indicators.entity.AreaCode;
import net.huashitong.Indicators.entity.IndexData;
import net.huashitong.Indicators.entity.OneIndex;
import net.huashitong.Indicators.requestModel.IndexRequestModel;

import net.huashitong.until.Until;
import net.huashitong.user.entity.Collection;
import net.huashitong.user.filter.CollectionFilter;
import net.huashitong.user.service.CollectionService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;


import static net.huashitong.Indicators.dataBean.StaticIndicators.*;
import static net.huashitong.Indicators.utils.DataFormateUntil.*;
import static net.huashitong.Indicators.utils.DataFormateUntil.kexuejishu;
import static net.huashitong.until.Until.JIDU_9DI;
import static net.huashitong.until.Until.YUEDU_9DI;
import static net.huashitong.until.Until.deepCopy;

/**
 * 所有二级页面
 */
@Service
public class ChildViewService {
    @Autowired
    private OneIndexService oneservice;

    @Autowired
    private AreaCodeService areaservice;

    @Autowired
    private IndexDataService dataService;

    @Autowired
    private CollectionService collectionService;

    @Autowired
    private RegionContrastService regionContrastService;

    @Autowired
    private AppApiService appApiService;

    public Map<String, Object> secondCatalogue(String codeId, String datetime, String codeType, String openId, String areaType) {
        //首页二级页面（福州不含平潭）数据处理，有以下几个指标：
        //地区生产总值、一产、二产、三产、社会消费品零售总额-->{福州=福州不含平潭}
        String db = YUEDU_9DI;
        if ("Y".equals(codeType)) {
            db = YUEDU_9DI;
        }
        if ("J".equals(codeType)) {
            db = JIDU_9DI;
        }
        //单位map
        Map<String, String> unitMap = Until.getUnit(db, codeId);

        if ((GDP_A.equals(codeId) && "E".equals(areaType) && "J".equals(codeType)) ||
                (GDP_B.equals(codeId) && "E".equals(areaType) && "J".equals(codeType)) ||
                (GDP_C.equals(codeId) && "E".equals(areaType) && "J".equals(codeType)) ||
                (GDP_D.equals(codeId) && "E".equals(areaType) && "J".equals(codeType))) {
            datetime = appApiService.dealWithQuarterTime(datetime);
        }


        if ((SHXFPLSZE.equals(codeId) && "E".equals(areaType) && "Y".equals(codeType)) ||
                (GDP_A.equals(codeId) && "E".equals(areaType) && "J".equals(codeType)) ||
                (GDP_B.equals(codeId) && "E".equals(areaType) && "J".equals(codeType)) ||
                (GDP_C.equals(codeId) && "E".equals(areaType) && "J".equals(codeType)) ||
                (GDP_D.equals(codeId) && "E".equals(areaType) && "J".equals(codeType))
        ) {
            List<IndexDataDTO> dataList = dataService.queryListIndexDate(codeId, datetime, null, codeType, areaType);
            String fzCumulative = "0";    //福州总量
            String fzCurrent = "0";       //福州当前值
            String fzRatio = "0";         //福州增长值
            for (IndexDataDTO dataDTO : dataList) {
                //获取福州的值
                if ("GX350100".equals(dataDTO.getAreaCode())) {
                    fzCumulative = kexuejishu(dataDTO.getCumulativeValue());
                    fzCurrent = kexuejishu(dataDTO.getCurrentValue());
                    fzRatio = dataDTO.getCumulativeRatio();
                }
            }
            //(GX350126):福州（不含平潭）
            for (IndexDataDTO dataDTO : dataList) {
                //设置福州（不含平潭）的值
                if ("GX350126".equals(dataDTO.getAreaCode())) {
                    if ("0".equals(dataDTO.getCumulativeValue())
                            /*|| "0".equals(dataDTO.getCurrentValue())*/
                            || "0".equals(dataDTO.getCumulativeRatio())) {
                        IndexData indexData = dataService.getIndexData(codeId, datetime, "GX350126", codeType, areaType);
                        indexData.setCumulativeValue(fzCumulative);
                        indexData.setCurrentValue(fzCurrent);
                        indexData.setCumulativeRatio(fzRatio);
                        dataService.update(indexData);
                    }
                }
            }
        }
        //---------------------------------------------------------------------------------------------
        //首页二级页面福州市数据处理，有以下几个指标：
        //进出口总额（WMJCKZE）、出口总额（CKZE）、实际利用外资（SJLYWZ）-->{福州市通过-->福州不含平潭与平潭的值进行计算}
        if ((WMJCKZE.equals(codeId)
                || CKZE.equals(codeId)
                || SJLYWZ.equals(codeId)) && "E".equals(areaType) && "Y".equals(codeType)) {
            List<IndexDataDTO> dataList = dataService.queryListIndexDate(codeId, datetime, null, codeType, areaType);
            String fznCumulative = "0";     //福州（不含平潭）总量
            String fznRatio = "0";          //福州（不含平潭）增长值
            String ptCumulative = "0";      //平潭总量
            String ptRatio = "0";           //平潭增长值
            for (IndexDataDTO dataDTO : dataList) {
                //获取福州（不含平潭）的值
                if ("GX350126".equals(dataDTO.getAreaCode())) {
                    fznCumulative = kexuejishu(dataDTO.getCumulativeValue());
                    fznRatio = dataDTO.getCumulativeRatio();
                }
                //获取平潭的值
                if ("GX350128".equals(dataDTO.getAreaCode())) {
                    ptCumulative = kexuejishu(dataDTO.getCumulativeValue());
                    ptRatio = dataDTO.getCumulativeRatio();
                }
            }
            //(GX350100):福州
            for (IndexDataDTO dataDTO : dataList) {
                //设置福州的值
                if ("GX350100".equals(dataDTO.getAreaCode())) {
                    if ("0".equals(dataDTO.getCumulativeValue())
                            || "0".equals(dataDTO.getCumulativeRatio())
                            || StringUtils.isBlank(dataDTO.getCumulativeValue())
                            || StringUtils.isBlank(dataDTO.getCumulativeRatio())) {
                        IndexData indexData = dataService.getIndexData(codeId, datetime, "GX350100", codeType, areaType);
                        if (!"0".equals(fznCumulative) && !"0".equals(ptCumulative)) {
                            double fzCumulative = Double.parseDouble(fznCumulative) + Double.parseDouble(ptCumulative);
                            indexData.setCumulativeValue(fzCumulative + "");
                            //((fznCumulative+ptCumulative)/(100*fznCumulative/(100+fznRatio)+100*ptCumulative/(100+ptRatio))-1.0)*100
                            double fzRatio = ((Double.parseDouble(fznCumulative) + Double.parseDouble(ptCumulative))
                                    / (100.0 * Double.parseDouble(fznCumulative) / (100.0 + Double.parseDouble(fznRatio)) +
                                    100.0 * Double.parseDouble(ptCumulative) / (100.0 + Double.parseDouble(ptRatio))) - 1.0) * 100;

                            indexData.setCumulativeRatio(fzRatio + "");
                            dataService.update(indexData);
                        }
                    }
                }
            }
        }

        //不传地区编码，获取全市
        // List<IndexDataDTO> data  = dataService.queryListIndexDate(codeId,datetime,null,codeType);
        List<AreaCode> arealist = areaservice.getCitysbyParentCode("GX35");
        List<Map<String, Object>> list = new ArrayList<>();
        // 封装指标编码与名称Map
        Map<String, String> codeMap = new HashMap<>();
        List<OneIndex> oneList = oneservice.getTwoNode(codeType, "", "E");
        for (OneIndex o : oneList) {
            if (!codeMap.containsKey(o.getCodeId())) {
                codeMap.put(o.getCodeId(), o.getCodeName());
            }
        }
        Map<String, String> areaCodes = new HashMap<>();
        Map<String, Object> map = new HashMap<>();
        String codeName;
        String ratioPTStr = "0";
        String cumulativePTStr = "0";
        String ratioNoPTStr = "0";
        String cumulativeNoPTStr = "0";
        String xmratio;
        String firstRatio = "0";
        List<IndexDataDTO> fistrank = null;
        for (AreaCode areaItem : arealist) {
            //去掉福州（不含平潭）
            if ("GX350126".equals(areaItem.getAreaCode())) {
                continue;
            }
            List<IndexDataDTO> data = dataService.queryListIndexDate(codeId, datetime, areaItem.getAreaCode(), codeType, areaType);
            if (data.size() == 0) {
                continue;
            }
            //如果平潭的累计个增长都为0怎不展示
            if ("GX350128".equals(areaItem.getAreaCode())) {
                if ("0".equals(data.get(0).getCumulativeValue()) && "0".equals(data.get(0).getCumulativeRatio())) {
                    continue;
                }
            }
            if ("GX350200".equals(areaItem.getAreaCode().trim())) {
                //涨幅含不含平潭安卓端接错了
                //排名情况：
                //增长值   含平潭
                List<IndexDataDTO> ratioPT = dataService.getRank(codeId, datetime, areaItem.getAreaCode(),
                        codeType, areaType, null, true);
                if (ObjectUtils.isNotBlank(ratioPT)) {
                    ratioNoPTStr = ratioPT.get(0).getRanks() + "";
                }
                //累计值   含平潭
                List<IndexDataDTO> cumulativePT = dataService.getRank(codeId, datetime, areaItem.getAreaCode(),
                        codeType, areaType, "cumulative_value", true);
                if (ObjectUtils.isNotBlank(cumulativePT)) {
                    cumulativePTStr = cumulativePT.get(0).getRanks() + "";
                }
                //增长值   不含平潭
                List<IndexDataDTO> ratioNoPT = dataService.getRank(codeId, datetime, areaItem.getAreaCode(),
                        codeType, areaType, null, false);
                if (ObjectUtils.isNotBlank(ratioNoPT)) {
                    List<IndexDataDTO> noPtRatio = dataService.queryListIndexDate(codeId, datetime, "GX350126", codeType, areaType);
                    if ("0".equals(noPtRatio.get(0).getCumulativeRatio()) || StringUtils.isBlank(noPtRatio.get(0).getCumulativeRatio())) {
                        ratioPTStr = ratioNoPTStr;
                    } else {
                        ratioPTStr = ratioNoPT.get(0).getRanks() + "";
                    }
                }
                //累计值   不含平潭
                List<IndexDataDTO> cumulativeNoPT = dataService.getRank(codeId, datetime, areaItem.getAreaCode(),
                        codeType, areaType, "cumulative_value", false);
                if (ObjectUtils.isNotBlank(cumulativeNoPT)) {
                    cumulativeNoPTStr = cumulativeNoPT.get(0).getRanks() + "";
                }
                xmratio = ObjectUtils.isBlank(data) ? "-" : dataFormat11(data.get(0).getCumulativeRatio());
                IndexData ranks = dataService.getRanks(datetime, codeType, areaType, codeId, "GX350200");
                map.put("codeId", codeId);
                if ("0".equals(data.get(0).getCumulativeValue())) {
                    data.get(0).setCumulativeValue(data.get(0).getCurrentValue());
                }
                codeName = data.get(0).getCodeName();
                map.put("codeName", codeName);
                map.put("areacode", ObjectUtils.isBlank(data) ? "-" : data.get(0).getAreaCode());
                map.put("areaName", ObjectUtils.isBlank(data) ? "-" : data.get(0).getAreaName());
                String unit = unitMap.get("unitname");

                map.put("unit", unit);
                //工业产销率-GMYSGY_CXL
                if (GMYSGY_CXL.equals(codeId)) {
                    map.put("cumulative", "-"/*StringUtils.isBlank(data.get(0).getCumulativeValue()) ? "0" :
                            dataFormat(kexuejishu(data.get(0).getCumulativeValue()))*/);
                    fistrank = dataService.getRank(codeId, datetime, null, codeType, areaType, "cumulative_value", true);
                    if (ObjectUtils.isNotBlank(fistrank)) {
                        firstRatio = ObjectUtils.isBlank(fistrank.get(0).getCumulativeRatio()) ? fistrank.get(1).getCumulativeValue() : fistrank.get(0).getCumulativeRatio();
                    }
                    xmratio = ObjectUtils.isBlank(data) ? "-" : dataFormat(data.get(0).getCumulativeValue());
                    map.put("ratio", xmratio);
                    map.put("unit", "-");
                } else {
                    map.put("cumulative", dataFormat(data.get(0).getCumulativeValue()));
                    fistrank = dataService.getRank(codeId, datetime, null, codeType, areaType, null, true);
                    if (ObjectUtils.isNotBlank(fistrank)) {
                        firstRatio = fistrank.get(0).getCumulativeRatio();
                    }
                    map.put("ratio", xmratio);
                }
                map.put("currentValue", ObjectUtils.isBlank(data) ? "-" : dataFormat(data.get(0).getCurrentValue()));
                map.put("datetime", ObjectUtils.isBlank(data) ? "-" : data.get(0).getDatetime());

                //实际利用外资增幅图表折线图应不显示，应无增幅排名
                //市国民经济主要指标固定资产投资，总量位次应留空
                /*if ("A050201".equals(codeId) && "Y".equals(codeType) && "E".equals(areaType)) {
                    map.put("ratioRank", "-");
                    map.put("ratioRankPT", "-");
                } else {
                    map.put("ratioRank", ratioPTStr);
                    map.put("ratioRankPT", ratioNoPTStr);
                }*/

                map.put("ratioRank", ratioPTStr);
                map.put("ratioRankPT", ratioNoPTStr);

                //市国民经济主要指标规模以上工业增加值（GMYSGY_ZJZ） 固定资产投资（GDZCTZ）总量位次应留空
                if (GMYSGY_ZJZ.equals(codeId) && "Y".equals(codeType) && "E".equals(areaType) ||
                        (GDZCTZ.equals(codeId) && "Y".equals(codeType) && "E".equals(areaType))) {
                    map.put("totalRank", "-");
                    map.put("totalRankPT", "-");
                } else {
                    map.put("totalRank", cumulativeNoPTStr);
                    map.put("totalRankPT", cumulativePTStr);
                }
                Double arcVal = ((Double.parseDouble(xmratio)) / (Double.parseDouble(firstRatio))) * 600;
                if (arcVal > 600.0) {
                    arcVal = 600.0;
                } else if (arcVal < 0) {
                    arcVal = 0.0;
                }
                if ("0".equals(firstRatio)) {
                    map.put("arcValue", "0");
                } else {
                    map.put("arcValue", NumberUtils.keepPrecision(0, arcVal) + "");
                }
            }
            if ("0".equals(data.get(0).getCumulativeValue())) {
                data.get(0).setCumulativeValue(data.get(0).getCurrentValue());
            }
            areaCodes.put(areaItem.getAreaCode(), areaItem.getAreaName());
            Map<String, Object> maptem = new HashMap<>();
            maptem.put("codeId", codeId);
            maptem.put("codeName", codeMap.get(codeId));
            maptem.put("areacode", areaItem.getAreaCode());
            maptem.put("areaName", areaItem.getAreaName());
            String unitV = unitMap.get("unitname");
            String vV = "0";
            if (ObjectUtils.isNotBlank(data)) {
                if (ObjectUtils.isNotBlank(data.get(0).getCumulativeValue())) {
                    vV = dataFormat(Double.parseDouble(data.get(0).getCumulativeValue()) + "");
                }
            }
            maptem.put("unit", unitV);

            //工业产销率
            if (GMYSGY_CXL.equals(codeId)) {
                maptem.put("unit", "%");
                maptem.put("cumulative", /*"0"*/ObjectUtils.isBlank(data) ? "0" : StringUtils.isBlank(data.get(0).getCumulativeValue()) ? "0" : dataFormat(data.get(0).getCumulativeValue()));
                maptem.put("ratio", ObjectUtils.isBlank(data) ? "0" : StringUtils.isBlank(data.get(0).getCumulativeRatio()) ? "0" : dataFormat(data.get(0).getCumulativeRatio()));
            } else {
                maptem.put("ratio", ObjectUtils.isBlank(data) ? "0" : StringUtils.isBlank(data.get(0).getCumulativeRatio()) ? "0" : dataFormat11(data.get(0).getCumulativeRatio()));
                maptem.put("cumulative", vV);
            }

            maptem.put("datetime", datetime);
            list.add(maptem);
        }
        List<Map<String, Object>> list2 = new ArrayList<>();

        for (Map<String, Object> areas1 : list) {
            if ("厦门市".equals(areas1.get("areaName"))) {
                list2.add(areas1);
            }
        }
        for (Map<String, Object> areas2 : list) {
            if ("厦门市".equals(areas2.get("areaName"))) {
                continue;
            }
            if ("平潭市".equals(areas2.get("areaName"))) {
                if (ObjectUtils.isBlank(areas2.get("ratio")) || "0".equals(areas2.get("ratio"))) {
                    continue;
                }
            }
            list2.add(areas2);
        }

        //无数据处理
        if (ObjectUtils.isBlank(areaCodes)) {
            map.put("showTab", new ArrayList<>());
            map.put("totalRank", "0");
            map.put("totalRankPT", "0");
            map.put("ratioRankPT", "0");
            map.put("ratioRank", "0");
            return map;
        }

        String areaNames = areaCodes.get(fistrank.get(0).getAreaCode());
        int flag = 0;
        for (int i = 1; i < fistrank.size(); i++) {
            if (dataFormat1(firstRatio).equals(dataFormat1(fistrank.get(i).getCumulativeRatio()))) {
                areaNames = areaNames + "、" + areaCodes.get(fistrank.get(i).getAreaCode());
                flag++;
            }
        }
        String res;
        if (flag > 8) {
            res = "";
        } else {
            //工业产销率
            if (GMYSGY_CXL.equals(codeId)) {
                res = areaNames + dataFormat2(firstRatio);
            } else {
                res = areaNames + dataFormat1(firstRatio);
            }
        }
        map.put("firstRatio", res);
        map.put("areaDate", list2);
        boolean ratioTab = false;
        boolean totalTab = false;
        for (Map<String, Object> object : list2) {
            if (!"0.0".equals(object.get("ratio")) && !"0".equals(object.get("ratio"))) {
                ratioTab = true;
            }

            if (!"0.0".equals(object.get("cumulative")) && !"0".equals(object.get("cumulative"))) {
                totalTab = true;
            }
        }
        List<String> strList = new ArrayList<>();
        if (totalTab) {
            strList.add("1");
        }
        if (ratioTab) {
            strList.add("2");
        }
        map.put("showTab", strList);

        if (!strList.contains("1") && !strList.contains("2")) {
            map.put("totalRank", "0");
            map.put("totalRankPT", "0");
            map.put("ratioRankPT", "0");
            map.put("ratioRank", "0");
        }
        return map;
    }


    /**
     * \三级页面指标数据
     *
     * @param codeId
     * @param datetime
     * @param arecode
     * @param codeType
     */
    public Map<String, Object> thirdCatalogue(String codeId, String datetime, String arecode, String codeType, String openId, String areaType) {
        if (StringUtils.isNotBlank(datetime)) {
            datetime = null;
        }
        List<IndexDataDTO> data = new ArrayList<>();
        //调整：旧版年度指标为月度指标，其数据为月度的12月份的累计； 之前的年度数据实则为年鉴数据
        if("T".equals(codeType)){
            codeType = "Y";
            List<IndexDataDTO> dataTemp = dataService.queryListIndexDate(codeId, StringUtils.isNotBlank(datetime) ? datetime.substring(0, 4) : null, arecode, "Y", areaType);
            //保留12月份数据
            for (IndexDataDTO dataDTO : dataTemp) {
                if("12".equals(dataDTO.getDatetime().substring(4,6))){
                    dataDTO.setCurrentValue("0");
//                    dataDTO.setCumulativeRatio("0");
                    dataDTO.setDatetime(dataDTO.getDatetime().substring(0,4));
                    data.add(dataDTO);
                }
            }
        }else{
            data = dataService.queryListIndexDate(codeId, StringUtils.isNotBlank(datetime) ? datetime.substring(0, 4) : null, arecode, codeType, areaType);

        }




        //两年
        /*String time1 = datetime.substring(0, 4);        //今年
        String time2 = Integer.parseInt(time1)-1+"";    //去年
        List<IndexDataDTO> data1 = dataService.queryListIndexDate(codeId, StringUtils.isNotBlank(datetime) ? time1 : null, arecode, codeType, areaType);
        List<IndexDataDTO> data2 = dataService.queryListIndexDate(codeId, StringUtils.isNotBlank(datetime) ? time2 : null, arecode, codeType, areaType);
        data2.addAll(data1);
        List<IndexDataDTO> data = new ArrayList<>();
        for(IndexDataDTO i : data2){
            if("01".equals(i.getDatetime().substring(4,6))){
                if(StringUtils.isBlank(i.getCumulativeRatio())||"0".equals(i.getCumulativeRatio()))
                    continue;
            }
            data.add(i);
        }*/

        for (IndexDataDTO d : data) {
            if (d.getCurrentValue().equals(d.getCumulativeValue())) {
                d.setCurrentValue("0");
            }
        }
        //获取单位
        String db = Until.getDBName(codeType, areaType);
        Map<String, String> resMap = Until.getUnit(db, codeId);

        Map<String, Object> resultMap = new HashMap<>();
        CollectionFilter filter = new CollectionFilter();
        filter.setCodeId(codeId);
        filter.setUserId(openId);
        filter.setAreaType(areaType);
        filter.setCodeType(codeType);
        filter.setAreaCode(arecode);
//        List<IndexData> indexData = dataService.getListIndexDate(codeId, arecode, codeType, datetime, areaType);
        List<Collection> collect = collectionService.query(filter);
        String iscollect = "0";
        String collectId = "0";
        if (ObjectUtils.isNotBlank(collect)) {
            iscollect = "1";
            collectId = collect.get(0).getSysId();
        }

        List<Map<String, Object>> listmap = new ArrayList<>();
        Collections.reverse(data);

        String flag1 = "1";
        String flag2 = "2";
        String flag3 = "3";
        for (IndexDataDTO dto : data) {
            if (!"0".equals(dto.getCurrentValue()) && ObjectUtils.isNotBlank(dto.getCurrentValue())) {
                flag1 = "0";
            }
            if (!"0".equals(dto.getCumulativeValue()) && ObjectUtils.isNotBlank(dto.getCumulativeValue())) {
                flag2 = "0";
            }
            if (!"0".equals(dto.getCumulativeRatio()) && ObjectUtils.isNotBlank(dto.getCumulativeRatio())) {
                flag3 = "0";
            }
            String totalValue = "0";
            String currentValue = "0";

            if (ObjectUtils.isNotBlank(dto.getCumulativeValue()) || ObjectUtils.isNotBlank(dto.getCurrentValue())) {
                totalValue = dataFormat(kexuejishu(StringUtils.isBlank(dto.getCumulativeValue()) ? "0" : dto.getCumulativeValue()));
                currentValue = dataFormat(kexuejishu(StringUtils.isBlank(dto.getCurrentValue()) ? "0" : dto.getCurrentValue()));


                //市级月度规模以上工业经济效益指标下的 规模以上工业企业单位数，增长不要，当月不要，个数都填在累计上
                if (("Y".equals(codeType) && "D".equals(areaType)) && (GMM1.equals(codeId) || GMM2.equals(codeId))) {
                    if ("0".equals(totalValue)) {
                        totalValue = currentValue;
                    }
                }

            }

            //如果三个值都没有，则过滤
            if ("0".equals(totalValue)) {
                if ("0".equals(currentValue)) {
                    if ("0".equals(dto.getCumulativeRatio())) {
                        continue;
                    }
                }
            }
            //全国月度->工业->工业主要产品（工业产品产量当月无值时不显示）
//            if ("G".equals(areaType) && "Y".equals(codeType) && "A0202".equals(codeId.substring(0, 5))) {
//                if ("0".equals(currentValue)) {
//                    continue;
//                }
//            }

            Map<String, Object> map = new HashMap<>();
            map.put("codeId", dto.getCodeId());
            map.put("codeName", dto.getCodeName());
            map.put("explanation", resMap.get("exp"));
            map.put("cumulative", StringUtils.isBlank(totalValue) ? "0" : totalValue);

            //工业产销率，不显示当月跟累计
            if (YDCXL.equals(codeId) && "Y".equals(codeType) && "D".equals(areaType)) {
                map.put("ratio", StringUtils.isBlank(dto.getCumulativeValue()) ? "0" : dataFormat2(dto.getCumulativeValue()));
            } else {
                map.put("ratio", StringUtils.isBlank(dto.getCumulativeRatio()) ? "0" : dataFormat11(dto.getCumulativeRatio()));
            }

            map.put("currentValue", StringUtils.isBlank(currentValue) ? "0" : currentValue);
            map.put("year", dto.getDatetime().substring(0, 4));
            map.put("month", Until.chartToMeam(dto.getDatetime().substring(4)));
            map.put("areCode", dto.getAreaCode());
            map.put("isCollected", iscollect);
            map.put("areaType", areaType);
            map.put("collectId", collectId);
            //接口返回工业产销率的单位是万元，实际是%
            if ("规模以上工业产销率".equals(dto.getCodeName())) {
                map.put("unit", "%");
            } else if (("Y".equals(codeType) && "D".equals(areaType)) && (
                    SS_SR_S1.equals(codeId) ||
                            SS_SR_S2.equals(codeId) ||
                            SS_SR_S3.equals(codeId) ||
                            SS_SR_S4.equals(codeId) ||
                            SS_SR_S5.equals(codeId) ||

                            CZ_ZC_JT.equals(codeId) ||
                            CZ_ZC_JY.equals(codeId) ||
                            CZ_ZC_KX.equals(codeId) ||
                            CZ_ZC_WS.equals(codeId) ||

                            //实际利用外资 的单位也是要改成亿元的(实际利用外资（人民币）、合同利用外资（人民币）)
                            "A090903".equals(codeId) ||
                            "A090905".equals(codeId) ||
                            //市级月度对外贸易， 进出口人民币的也是要都改成亿元
                            "A090401".equals(codeId) ||
                            //人民币
                            codeId.startsWith("A0905") ||
                            codeId.startsWith("A0906") ||
                            //市级月度投资下单位是亿元（固定资产投资）
                            codeId.startsWith("A05") ||

                            codeId.startsWith(GNMY)
            )) {
                //市级月度财政下的财政收入下的增值税到非税收入的单位都改成亿元单位
                //财政总收入_地方级财政收入_税收收入_增值税
                //财政总收入_地方级财政收入_税收收入_改征增值税
                //财政总收入_地方级财政收入_税收收入_企业所得税（40%）
                //财政总收入_地方级财政收入_税收收入_个人所得税（40%）
                //财政总收入_地方级财政收入_非税收入

                //市级月度财政下的财政支出下的交通运输到医疗卫生的单位都改成亿元单位
                //财政支出_交通运输
                //财政支出教育
                //财政支出_科学技术
                //财政支出_医疗卫生

                //市级月度国内贸易下面所有单位改成亿元

                if ("万元".equals(resMap.get("unitname"))) {
                    map.put("cumulative", StringUtils.isBlank(totalValue) ? "0" : dataformatUnit(totalValue));
                    map.put("currentValue", StringUtils.isBlank(currentValue) ? "0" : dataformatUnit(currentValue));
                    map.put("unit", "亿元");
                }
            } else {
//                if ("万元".equals(resMap.get("unitname")) && ((String) map.get("currentValue")).length() > 5 && ((String) map.get("cumulative")).length() > 5) {
//                    map.put("cumulative", StringUtils.isBlank(vV) ? "0" : dataformatUnit(vV));
//                    map.put("currentValue", StringUtils.isBlank(dV) ? "0" : dataformatUnit(dV));
//                    map.put("unit", "亿元");
//                }
//                //---------------------------------------
//                else if ("千美元".equals(resMap.get("unitname")) && ((String) map.get("currentValue")).length() > 5 && ((String) map.get("cumulative")).length() > 5) {
//                    map.put("cumulative", StringUtils.isBlank(vV) ? "0" : dataformatQianUnit(vV));
//                    map.put("currentValue", StringUtils.isBlank(dV) ? "0" : dataformatQianUnit(dV));
//                    map.put("unit", "亿美元");
//                } else if ("千美元".equals(resMap.get("unitname")) && ((String) map.get("currentValue")).length() > 5 && !"0".equals(flag2)) {
//                    map.put("currentValue", StringUtils.isBlank(dV) ? "0" : dataformatQianUnit(dV));
//                    map.put("unit", "亿美元");
//                } else if ("千美元".equals(resMap.get("unitname")) && ((String) map.get("cumulative")).length() > 5 && !"0".equals(flag1)) {
//                    map.put("cumulative", StringUtils.isBlank(vV) ? "0" : dataformatQianUnit(vV));
//                    map.put("unit", "亿美元");
//                } else if ("千美元".equals(resMap.get("unitname")) && ((String) map.get("cumulative")).length() > 5 && "0".equals((String) map.get("currentValue"))) {
//                    map.put("cumulative", StringUtils.isBlank(vV) ? "0" : dataformatQianUnit(vV));
//                    map.put("unit", "亿美元");
//                } else if ("千美元".equals(resMap.get("unitname")) && ((String) map.get("currentValue")).length() > 5 && "0".equals((String) map.get("cumulative"))) {
//                    map.put("currentValue", StringUtils.isBlank(dV) ? "0" : dataformatQianUnit(dV));
//                    map.put("unit", "亿美元");
//                }
//                //---------------------------------------
//                else if ("百万美元".equals(resMap.get("unitname")) && ((String) map.get("currentValue")).length() > 5 && ((String) map.get("cumulative")).length() > 5) {
//                    map.put("cumulative", StringUtils.isBlank(vV) ? "0" : dataformatBaiWangToYi(vV));
//                    map.put("currentValue", StringUtils.isBlank(dV) ? "0" : dataformatBaiWangToYi(dV));
//                    map.put("unit", "亿美元");
//                } else if ("百万美元".equals(resMap.get("unitname")) && ((String) map.get("currentValue")).length() > 5 && !"0".equals(flag2)) {
//                    map.put("currentValue", StringUtils.isBlank(dV) ? "0" : dataformatBaiWangToYi(dV));
//                    map.put("unit", "亿美元");
//                } else if ("百万美元".equals(resMap.get("unitname")) && ((String) map.get("cumulative")).length() > 5 && !"0".equals(flag1)) {
//                    map.put("cumulative", StringUtils.isBlank(vV) ? "0" : dataformatBaiWangToYi(vV));
//                    map.put("unit", "亿美元");
//                } else if ("百万美元".equals(resMap.get("unitname")) && ((String) map.get("cumulative")).length() > 5 && "0".equals((String) map.get("currentValue"))) {
//                    map.put("cumulative", StringUtils.isBlank(vV) ? "0" : dataformatBaiWangToYi(vV));
//                    map.put("unit", "亿美元");
//                } else if ("百万美元".equals(resMap.get("unitname")) && ((String) map.get("currentValue")).length() > 5 && "0".equals((String) map.get("cumulative"))) {
//                    map.put("currentValue", StringUtils.isBlank(dV) ? "0" : dataformatBaiWangToYi(dV));
//                    map.put("unit", "亿美元");
//                }
//                //---------------------------------------
//                else if ("万元".equals(resMap.get("unitname")) && ((String) map.get("currentValue")).length() > 5 && !"0".equals(flag2)) {
//                    map.put("currentValue", StringUtils.isBlank(dV) ? "0" : dataformatUnit(dV));
//                    map.put("unit", "亿元");
//                } else if ("万元".equals(resMap.get("unitname")) && ((String) map.get("cumulative")).length() > 5 && !"0".equals(flag1)) {
//                    map.put("cumulative", StringUtils.isBlank(vV) ? "0" : dataformatUnit(vV));
//                    map.put("unit", "亿元");
//                } else if ("万元".equals(resMap.get("unitname")) && ((String) map.get("cumulative")).length() > 5 && "0".equals((String) map.get("currentValue"))) {
//                    map.put("cumulative", StringUtils.isBlank(vV) ? "0" : dataformatUnit(vV));
//                    map.put("unit", "亿元");
//                } else if ("万元".equals(resMap.get("unitname")) && ((String) map.get("currentValue")).length() > 5 && "0".equals((String) map.get("cumulative"))) {
//                    map.put("currentValue", StringUtils.isBlank(dV) ? "0" : dataformatUnit(dV));
//                    map.put("unit", "亿元");
//                } else {
//                    map.put("unit", resMap.get("unitname"));
//                }
                map.put("unit", resMap.get("unitname"));
            }
            listmap.add(map);
        }
        resultMap.put("listData", listmap);
        StringBuffer showTab = new StringBuffer();
        if ("0".equals(flag1)) {
            //24、商品房待售情况不要当月值
            if ("A060401".equals(codeId) && "D".equals(areaType) && "Y".equals(codeType)) {

            } else if ("A060402".equals(codeId) && "D".equals(areaType) && "Y".equals(codeType)) {

            } else if ("A060403".equals(codeId) && "D".equals(areaType) && "Y".equals(codeType)) {

            } else if ("A060404".equals(codeId) && "D".equals(areaType) && "Y".equals(codeType)) {

            } else {
                showTab.append("1");
            }
        }


        //九地市当月均不显示(市级GPD不显示当季值)
        if ("E".equals(areaType)
                || (GDP_A_D.equals(codeId) && "D".equals(areaType) && "J".equals(codeType))
                || (GDP_B_D.equals(codeId) && "D".equals(areaType) && "J".equals(codeType))
                || (GDP_C_D.equals(codeId) && "D".equals(areaType) && "J".equals(codeType))
                || (GDP_D_D.equals(codeId) && "D".equals(areaType) && "J".equals(codeType))
                || (GDP_A1_D.equals(codeId) && "D".equals(areaType) && "J".equals(codeType))
                || (GDP_A2_D.equals(codeId) && "D".equals(areaType) && "J".equals(codeType))
                || (GDP_A3_D.equals(codeId) && "D".equals(areaType) && "J".equals(codeType))
                || (GDP_A4_D.equals(codeId) && "D".equals(areaType) && "J".equals(codeType))
                || (GDP_A5_D.equals(codeId) && "D".equals(areaType) && "J".equals(codeType))
                || (GDP_A6_D.equals(codeId) && "D".equals(areaType) && "J".equals(codeType))
                || (GDP_A7_D.equals(codeId) && "D".equals(areaType) && "J".equals(codeType))
                || (GDP_A8_D.equals(codeId) && "D".equals(areaType) && "J".equals(codeType))
                || (GDP_A9_D.equals(codeId) && "D".equals(areaType) && "J".equals(codeType))
                || (GDP_AA_D.equals(codeId) && "D".equals(areaType) && "J".equals(codeType))) {
            showTab.setLength(0);
        }
        if ("0".equals(flag2)) {
            showTab.append("2");
        }
        if ("0".equals(flag3)) {
            showTab.append("3");
        }
        //工业产销率，不显示当月跟累计
        if (YDCXL.equals(codeId) && "Y".equals(codeType) && "D".equals(areaType)) {
            showTab.setLength(0);
            showTab.append("3");
        }

        //区域比较全国主要经济指标季度地区生产总值增长那一栏不要了
        if (QGJD_GDP.equals(codeId) && "J".equals(codeType) && "G".equals(areaType)) {
            showTab.setLength(0);
            showTab.append("2");
        }

        //市级月度价格指教下的居民消费总指数上年同月=100、上年同期=100的增长那一列都要删掉
        if (JMXF_index_1.equals(codeId) && "Y".equals(codeType) && "D".equals(areaType)) {
            showTab.setLength(0);
            showTab.append("12");
        }

        //市级月度规模以上工业经济效益指标下的 规模以上工业企业单位数，增长不要，当月不要，个数都填在累计上
        if ((GMM1.equals(codeId) || GMM2.equals(codeId)) && "Y".equals(codeType) && "D".equals(areaType)) {
            showTab.setLength(0);
            showTab.append("2");
        }

        resultMap.put("showTab", showTab.toString());
        return resultMap;
    }


    public List<Map<String, Object>> getCountryView(IndexRequestModel filter) {

        //获取一级指标
        //oneservice.getTwoNode()
        // List<IndexDataDTO> arr1 =  dataService.queryListIndexDate(filter.getCodeId(),filter.getDateTime(),filter.getAreaCode(),filter.getCodeType(),filter.getAreaType());
        List<Map<String, Object>> listmap = new ArrayList<>();

        //获取全国指标的目录。
        // List<OneIndex> oneindex = oneservice.getViews("G", "1", null);
        List<IndexDataDTO> data = null;

        String[] indexs = {"A030101", "A040101", "A050101", "A010302", "A010201"};

        for (String item : indexs) {
            Map<String, Object> map1 = new HashMap<>();
          /*  data = dataService.queryListIndexDate(item.getCodeId(), filter.getDateTime(), filter.getAreaCode(), filter.getCodeType(), filter.getAreaType());
            map1.put("codeId", item.getCodeId());
            map1.put("codeName", item.getCodeName());
            map1.put("areaCode", filter.getAreaCode());*/

            data = dataService.queryListIndexDate(item, filter.getDateTime(), filter.getAreaCode(), filter.getCodeType(), filter.getAreaType());
            map1.put("mintitle", "增幅");
            map1.put("unit", "%");
            map1.put("codeId", item);
            map1.put("codeName", data.get(0).getCodeName());
            map1.put("areaCode", filter.getAreaCode());
            map1.put("cumulative", "总量" + (ObjectUtils.isBlank(data) ? "-" : data.get(0).getCumulativeValue() + (StringUtils.isBlank(data.get(0).getUnit()) ? "亿元" : data.get(0).getUnit())));
            map1.put("datetime", filter.getDateTime());
            map1.put("ratio", ObjectUtils.isBlank(data) ? "-" : data.get(0).getCumulativeRatio());
            map1.put("areaTpe", filter.getAreaType());
            map1.put("codeType", filter.getCodeType());
            //获取二级指标

            List<Map<String, Object>> listmap2 = new ArrayList<>();
             /*List<OneIndex> oneindex2 = oneservice.getViews("G", "2", item.getCodeId());
          for (OneIndex item2 : oneindex2) {
                Map<String, Object> map2 = new HashMap<>();
                data = dataService.queryListIndexDate(item2.getCodeId(), filter.getDateTime(), filter.getAreaCode(), filter.getCodeType(), filter.getAreaType());
                map2.put("areaCode", filter.getAreaCode());
                map2.put("childCodeId", item2.getCodeId());
                map2.put("childCodeName", item2.getCodeName());
                map2.put("cumulative", "总量" + (ObjectUtils.isBlank(data) ? "-" : data.get(0).getCumulativeValue() + (StringUtils.isBlank(data.get(0).getUnit()) ? "亿元" : data.get(0).getUnit())));
                map2.put("datetime", ObjectUtils.isBlank(data) ? "-" : data.get(0).getDatetime());
                map2.put("ratio", ObjectUtils.isBlank(data) ? "-" : StringUtils.isBlank(data.get(0).getCumulativeRatio()) ? "-" : data.get(0).getCumulativeRatio());
                map2.put("areaTpe", filter.getAreaType());
                map2.put("codeType", filter.getCodeType());
                listmap2.add(map2);

            }*/

            map1.put("child", listmap2);
            listmap.add(map1);


        }

/*
       String[] arr = {"国内生产总值(GDP)", "规模以上工业增加值", "固定资产投资(不含农户)",
                "社会消费品零售总额", "对外贸易进出口额", "财政总收入", "财政支出"
                , "批准直接利用外资合同款", "实际利用外商直接投资", "城镇居民人均可支配收入"
                , "农村居民人均可支配收入", "居民消费价格总指数", "工业生产者出厂价格指数"
                , "商品零售价指数"};
        int flagInt = 1;
        for(String item:arr){
            List<Map<String, Object>> childList = new ArrayList<>();
            Map<String, Object> map = new HashMap<>();

            String indexCode = "A0"+flagInt;
            map.put("codeId",indexCode);
            map.put("codeName",item);
            float zongliang = (float) (Math.random()*10000);
            map.put("cumulative",zongliang+"亿元");

            NumberFormat ddf1=NumberFormat.getNumberInstance() ;
            ddf1.setMaximumFractionDigits(2);
            float add = (float) (Math.random()*12);
            map.put("ratio",ddf1.format(add));
            map.put("group","1");
            map.put("datetime","20383838");
            int flag2Int = 1;
            for(int i=0; i<2 ;i++){
                Map<String, Object> childMap = new HashMap<>();
                String childIndexCode = "B0"+flag2Int+flagInt*2;
                childMap.put("childCodeId",childIndexCode);
                childMap.put("childCodeName","二级指标");
                childMap.put("cumulative","1000亿元");
                childMap.put("ratio","12");
                childMap.put("group","2");
                childMap.put("datetime","20383838");
                flag2Int++;
                childList.add(childMap);
            }
            flagInt++;
            map.put("child",childList);
            list.add(map);
        }*/
        return listmap;
    }


    /**
     * 老旧的接口
     *
     * @param codeId
     * @param codeType
     * @param datetime
     * @param areaType
     * @return
     */
    public Map<String, Object> fifteencitydata(String codeId, String codeType, String datetime, String areaType, String areacode) {
//        if ("J".equals(codeType)) {
//            datetime = jiduTimeFormat(datetime);
//        }
        StringBuffer codeTypeTemp = new StringBuffer(codeType);
        if("T".equals(codeType)){
            codeType = "Y";
        }
        List<Map<String, Object>> list = new ArrayList<>();
        // Map<String,Object> parent  = new HashMap<>();
        Map<String, Object> quanGuoMap = new HashMap<>();
        String db = Until.getDBName(codeType, areaType);
        Map<String, String> resMap = Until.getUnit(db, codeId);

        /** A 区级 B 四个特区，C 十五个副省级 D 市级数据，E 九地市  G 全国
         *
         **/
        List<IndexDataDTO> fifteencity = null;
        List<List<Map<String, Object>>> resultList = new ArrayList<>();
        if ("C".equals(areaType.trim())) {
            if ("J".equals(codeType)) {
                datetime = timeToJiduFormat(datetime);
            }
            // List<IndexDataDTO>  fifteenCity = dataService.queryListIndexDate(codeId,datetime,null,codeType,areaType);
            fifteencity = dataService.getCityValues(codeId, datetime, areacode, codeType, areaType);

            int rank = 1;
            int i = 0;
            String flag1 = "1";
            String flag2 = "2";
            String flag3 = "3";

            for (IndexDataDTO city : fifteencity) {
                if (!"0".equals(city.getCurrentValue()) && ObjectUtils.isNotBlank(city.getCurrentValue())) {
                    flag1 = "0";
                }
                if (!"0".equals(city.getCumulativeValue()) && ObjectUtils.isNotBlank(city.getCumulativeValue())) {
                    flag2 = "0";
                }
                if (!"0".equals(city.getCumulativeRatio()) && ObjectUtils.isNotBlank(city.getCumulativeRatio())) {
                    flag3 = "0";
                }
            }
            StringBuffer showTab = new StringBuffer();
            if ("0".equals(flag1) && "2".equals(flag2) && "N".equals(codeType)) {
                showTab.append("2");
                for (IndexDataDTO city : fifteencity) {
                    Map<String, Object> map = new HashMap<>();
                    if ("J".equals(codeType)) {
                        datetime = jiduTimeFormat(datetime);
                    }
                    String citycumValue = "";
                    String currentValue = "";
                    if (ObjectUtils.isNotBlank(city)) {
                        if (ObjectUtils.isNotBlank(city.getCumulativeValue())) {
                            if ("万元".equals(resMap.get("unitname"))) {
                                citycumValue = dataformatUnit(kexuejishu(city.getCurrentValue()));
                                currentValue = dataformatUnit(kexuejishu(city.getCurrentValue()));
                                map.put("unit", "亿元");
                            } else {
                                citycumValue = dataFormat(kexuejishu(city.getCurrentValue()));
                                currentValue = dataFormat(kexuejishu(city.getCurrentValue()));
                                map.put("unit", resMap.get("unitname"));
                            }

                        }
                    }

                    map.put("datetime", datetime);
                    map.put("areaName", city.getAreaName());
                    map.put("areaCode", city.getAreaCode());
                    map.put("currentValue", currentValue);
                    map.put("rank", StringUtils.isBlank(city.getRanks().toString()) ? "0" : city.getRanks());
                    //map.put("currentValue","878454");
//                map.put("unit", resMap.get("unitname"));
                    map.put("cumulative", citycumValue);
                    map.put("ratio", StringUtils.isBlank(city.getCumulativeRatio()) ? "0" : dataFormat1(city.getCumulativeRatio()));
                    rank++;
                    i++;
                    list.add(map);
                }
            } else {
                for (IndexDataDTO city : fifteencity) {
                    Map<String, Object> map = new HashMap<>();
                    if ("J".equals(codeType)) {
                        datetime = jiduTimeFormat(datetime);
                    }
                    String citycumValue = "";
                    String currentValue = "";
                    if (ObjectUtils.isNotBlank(city)) {
                        if (ObjectUtils.isNotBlank(city.getCumulativeValue())) {
                            if ("万元".equals(resMap.get("unitname"))) {
                                citycumValue = dataformatUnit(kexuejishu(city.getCumulativeValue()));
                                currentValue = dataformatUnit(kexuejishu(city.getCurrentValue()));
                                map.put("unit", "亿元");
                            } else {
                                citycumValue = dataFormat(kexuejishu(city.getCumulativeValue()));
                                currentValue = dataFormat(kexuejishu(city.getCurrentValue()));
                                map.put("unit", resMap.get("unitname"));
                            }

                        }
                    }

                    map.put("datetime", datetime);
                    map.put("areaName", city.getAreaName());
                    map.put("areaCode", city.getAreaCode());
                    map.put("currentValue", currentValue);
                    map.put("rank", StringUtils.isBlank(city.getRanks().toString()) ? "0" : city.getRanks());
                    //map.put("currentValue","878454");
//                map.put("unit", resMap.get("unitname"));
                    map.put("cumulative", citycumValue);
                    map.put("ratio", StringUtils.isBlank(city.getCumulativeRatio()) ? "0" : dataFormat1(city.getCumulativeRatio()));
                    rank++;
                    i++;
                    list.add(map);
                }
            }


            if ("0".equals(flag1)) {
                //副省级不显示当月如果要显示改为1 showTab.append("1");
            }
            if ("0".equals(flag2)) {
                showTab.append("2");
            }
            if ("0".equals(flag3)) {
                showTab.append("3");
            }
            List<Map<String, Object>> list1 = new ArrayList<>();
            list1.addAll(list);
            Collections.sort(list1, new Comparator<Map<String, Object>>() {
                @Override
                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                    String val1 = (String) o1.get("currentValue");
                    if (StringUtils.isBlank(val1)) {
                        val1 = "0";
                    }
                    Double valDouble1 = Double.parseDouble(val1);
                    String val2 = (String) o2.get("currentValue");
                    if (StringUtils.isBlank(val2)) {
                        val2 = "0";
                    }
                    Double valDouble2 = Double.parseDouble(val2);
                    if (valDouble1 > valDouble2) {

                        return -1;
                    } else if (valDouble1 < valDouble2) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            });
            List<Map<String, Object>> list2 = new ArrayList<>();
            list2.addAll(list);
            Collections.sort(list2, new Comparator<Map<String, Object>>() {
                @Override
                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                    String val1 = (String) o1.get("cumulative");
                    if (StringUtils.isBlank(val1)) {
                        val1 = "0";
                    }
                    Double valDouble1 = Double.parseDouble(val1);
                    String val2 = (String) o2.get("cumulative");
                    if (StringUtils.isBlank(val2)) {
                        val2 = "0";
                    }
                    Double valDouble2 = Double.parseDouble(val2);
                    if (valDouble1 > valDouble2) {
                        return -1;
                    } else if (valDouble1 < valDouble2) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            });
            List<Map<String, Object>> list3 = new ArrayList<>();
            list3.addAll(list);
            Collections.sort(list3, new Comparator<Map<String, Object>>() {
                @Override
                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                    String val1 = (String) o1.get("ratio");
                    Double valDouble1 = Double.parseDouble(val1);
                    String val2 = (String) o2.get("ratio");
                    Double valDouble2 = Double.parseDouble(val2);
                    if (valDouble1 > valDouble2) {
                        return -1;
                    } else if (valDouble1 < valDouble2) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            });
            List<Map<String, Object>> s1 = restRank(fifteenRankAndColor(deepCopy(list1)), "1");
            List<Map<String, Object>> s2 = restRank(fifteenRankAndColor(deepCopy(list2)), "2");
            List<Map<String, Object>> s3 = restRank(fifteenRankAndColor(deepCopy(list3)), "3");

            //true 的话头部排名要留空
            boolean f1 = true;
            boolean f2 = true;
            boolean f3 = true;
            for (Map<String, Object> s : s1) {
                if (("0".equals(s.get("currentValue"))
                        || "0.0".equals(s.get("currentValue"))
                        || ObjectUtils.isBlank(s.get("currentValue")))
                        && (Integer) s.get("rank") == 2) {
                    f1 = false;
                } else {
                    f1 = true;
                }
                if ("3".equals(s.get("rank"))) {
                    f1 = true;
                }
            }
            for (Map<String, Object> s : s2) {
                if (("0".equals(s.get("cumulative"))
                        || "0.0".equals(s.get("cumulative"))
                        || ObjectUtils.isBlank(s.get("cumulative")))
                        && (Integer) s.get("rank") == 2) {
                    f2 = false;
                } else {
                    f2 = true;
                }
                if ("3".equals(s.get("rank"))) {
                    f2 = true;
                }
            }
            for (Map<String, Object> s : s3) {
                if (("0".equals(s.get("ratio"))
                        || "0.0".equals(s.get("ratio"))
                        || ObjectUtils.isBlank(s.get("ratio")))
                        && (Integer) s.get("rank") == 2) {
                    f3 = false;
                } else {
                    f3 = true;
                    break;
                }
                if ("3".equals(s.get("rank"))) {
                    f3 = true;
                    break;
                }
            }

            if (("A050201".equals(codeId) || "A050202".equals(codeId))
                    && "N".equals(codeType)) {
                f1 = false;
                f2 = false;
                f3 = false;
            }

            if (("A030201".equals(codeId) || "A030202".equals(codeId))
                    && "Y".equals(codeType)) {
                f1 = false;
                f2 = false;
                f3 = false;
            }
            resultList.add(s1);
            resultList.add(s2);
            resultList.add(s3);
            quanGuoMap.put("list", resultList);
            quanGuoMap.put("f1", f1);
            quanGuoMap.put("f2", f2);
            quanGuoMap.put("f3", f3);
            quanGuoMap.put("showTab", showTab);
        }
        if ("A".equals(areaType)) {
            quanGuoMap = regionContrastService.regionContrastProcess(codeId, datetime, codeType, areacode, areaType, resMap, codeTypeTemp.toString());
        }
        if ("B".equals(areaType)) {   //  四个经济特区
            if ("J".equals(codeType)) {
                datetime = timeToJiduFormat(datetime);
            }
            fifteencity = dataService.getCityValues(codeId, datetime, areacode, codeType, areaType);
            int rank = 1;

            if ("J".equals(codeType)) {
                datetime = jiduTimeFormat(datetime);
            }
            quanGuoMap.put("datetime", datetime);

            String flag1 = "1";
            String flag2 = "2";
            String flag3 = "3";

            for (IndexDataDTO city : fifteencity) {
                if (!"0".equals(city.getCurrentValue()) && ObjectUtils.isNotBlank(city.getCurrentValue())) {
                    flag1 = "0";
                }
                if (!"0".equals(city.getCumulativeValue()) && ObjectUtils.isNotBlank(city.getCumulativeValue())) {
                    flag2 = "0";
                }
                if (!"0".equals(city.getCumulativeRatio()) && ObjectUtils.isNotBlank(city.getCumulativeRatio())) {
                    flag3 = "0";
                }
            }
            StringBuffer showTab = new StringBuffer();
            //（年度）如果当前值有值，累计值没有值
            if ("0".equals(flag1) && "2".equals(flag2) && "N".equals(codeType)) {
                showTab.append("2");
                for (IndexDataDTO city : fifteencity) {

                    Map<String, Object> map = new HashMap<>();
                    map.put("areaName", city.getAreaName());
                    map.put("areaCode", city.getAreaCode());
                    if ("J".equals(codeType)) {
                        datetime = jiduTimeFormat(datetime);
                    }
                    map.put("datetime", datetime);
                    map.put("unit", resMap.get("unitname"));
                    map.put("currentValue",
                            ObjectUtils.isBlank(city) ? "0" : StringUtils.isBlank(city.getCurrentValue()) ? "0" :
                                    dataFormat(Double.parseDouble(kexuejishu(city.getCurrentValue())) /*/ 10000*/ + ""));
                    map.put("rank", StringUtils.isBlank(city.getRanks().toString()) ? "0" : city.getRanks());
                    map.put("cumulative",
                            ObjectUtils.isBlank(city) ? "0" : StringUtils.isBlank(city.getCurrentValue()) ? "0" :
                                    dataFormat(Double.parseDouble(kexuejishu(city.getCurrentValue())) /*/ 10000 */ + ""));
                    map.put("ratio", StringUtils.isBlank(city.getCumulativeRatio()) ? "0" : dataFormat1(city.getCumulativeRatio()));

                    rank++;
                    list.add(map);
                }
            } else {
                for (IndexDataDTO city : fifteencity) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("areaName", city.getAreaName());
                    map.put("areaCode", city.getAreaCode());
                    if ("J".equals(codeType)) {
                        datetime = jiduTimeFormat(datetime);
                    }
                    map.put("datetime", datetime);
                    map.put("unit", resMap.get("unitname"));
                    map.put("currentValue",
                            ObjectUtils.isBlank(city) ? "0" : StringUtils.isBlank(city.getCurrentValue()) ? "0" :
                                    dataFormat(Double.parseDouble(kexuejishu(city.getCurrentValue())) /*/ 10000*/ + ""));
                    map.put("rank", StringUtils.isBlank(city.getRanks().toString()) ? "0" : city.getRanks());
                    map.put("cumulative",
                            ObjectUtils.isBlank(city) ? "0" : StringUtils.isBlank(city.getCumulativeValue()) ? "0" :
                                    dataFormat(Double.parseDouble(kexuejishu(city.getCumulativeValue())) /*/ 10000 */ + ""));
                    map.put("ratio", StringUtils.isBlank(city.getCumulativeRatio()) ? "0" : dataFormat1(city.getCumulativeRatio()));

                    rank++;
                    list.add(map);
                }
            }


            if ("0".equals(flag1)) {
                //四个经济特区当月不显示，如果要显示改为1 showTab.append("1");
            }
            if ("0".equals(flag2)) {
                showTab.append("2");
            }
            if ("0".equals(flag3)) {
                showTab.append("3");
            }

            List<Map<String, Object>> list1 = new ArrayList<>();
            list1.addAll(list);
            Collections.sort(list1, new Comparator<Map<String, Object>>() {
                @Override
                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                    String val1 = (String) o1.get("currentValue");
                    Double valDouble1 = Double.parseDouble(val1);
                    String val2 = (String) o2.get("currentValue");
                    Double valDouble2 = Double.parseDouble(val2);
                    if (valDouble1 > valDouble2) {

                        return -1;
                    } else if (valDouble1 < valDouble2) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            });
            List<Map<String, Object>> list2 = new ArrayList<>();
            list2.addAll(list);
            Collections.sort(list2, new Comparator<Map<String, Object>>() {
                @Override
                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                    String val1 = (String) o1.get("cumulative");
                    Double valDouble1 = Double.parseDouble(val1);
                    String val2 = (String) o2.get("cumulative");
                    Double valDouble2 = Double.parseDouble(val2);
                    if (valDouble1 > valDouble2) {
                        return -1;
                    } else if (valDouble1 < valDouble2) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            });
            List<Map<String, Object>> list3 = new ArrayList<>();
            list3.addAll(list);
            Collections.sort(list3, new Comparator<Map<String, Object>>() {
                @Override
                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                    String val1 = (String) o1.get("ratio");
                    Double valDouble1 = Double.parseDouble(val1);
                    String val2 = (String) o2.get("ratio");
                    Double valDouble2 = Double.parseDouble(val2);
                    if (valDouble1 > valDouble2) {
                        return -1;
                    } else if (valDouble1 < valDouble2) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            });

            List<Map<String, Object>> s1 = restRank(fourRankAndColor(deepCopy(list1)), "1");
            List<Map<String, Object>> s2 = restRank(fourRankAndColor(deepCopy(list2)), "2");
            List<Map<String, Object>> s3 = restRank(fourRankAndColor(deepCopy(list3)), "3");

            //true 的话头部要排名
            boolean f1 = true;
            boolean f2 = true;
            boolean f3 = true;
            for (Map<String, Object> s : s1) {
                if (("0".equals(s.get("currentValue"))
                        || "0.0".equals(s.get("currentValue"))
                        || ObjectUtils.isBlank(s.get("currentValue")))
                        && (Integer) s.get("rank") == 2) {
                    f1 = false;
                } else {
                    f1 = true;
                }
                if ("3".equals(s.get("rank"))) {
                    f1 = true;
                    break;
                }
            }
            for (Map<String, Object> s : s2) {
                if (("0".equals(s.get("cumulative"))
                        || "0.0".equals(s.get("cumulative"))
                        || ObjectUtils.isBlank(s.get("cumulative")))
                        && (Integer) s.get("rank") == 2) {
                    f2 = false;
                } else {
                    f2 = true;
                }
                if ("3".equals(s.get("rank"))) {
                    f2 = true;
                }
            }
            for (Map<String, Object> s : s3) {
                if (("0".equals(s.get("ratio"))
                        || "0.0".equals(s.get("ratio"))
                        || ObjectUtils.isBlank(s.get("ratio")))
                        && (Integer) s.get("rank") == 2) {
                    f3 = false;
                } else {
                    f3 = true;
                    break;
                }
                if ("3".equals(s.get("rank"))) {
                    f3 = true;
                    break;
                }
            }

            //排名：外商xxx不需要排名
            if (("A040201".equals(codeId) || "A040202".equals(codeId) || "A040203".equals(codeId) || "A040204".equals(codeId))
                    && "Y".equals(codeType)) {
                f1 = false;
                f2 = false;
                f3 = false;
            }
            //排名：外商xxx不需要排名
            if ("A050201".equals(codeId)
                    && "N".equals(codeType)) {
                f1 = false;
                f2 = false;
                f3 = false;
            }

            resultList.add(s1);
            resultList.add(s2);
            resultList.add(s3);
            quanGuoMap.put("list", resultList);
            quanGuoMap.put("f1", f1);
            quanGuoMap.put("f2", f2);
            quanGuoMap.put("f3", f3);
            quanGuoMap.put("showTab", showTab);
        }
        if ("E".equals(areaType)) {
            String unit = "";
            if ("J".equals(codeType)) {
                datetime = timeToJiduFormat(datetime);
            }
            fifteencity = dataService.getCityValuesNoPt(codeId, datetime, areacode, codeType, areaType);


            //规模以上工业产销率
            if ("A010201".equals(codeId) && "Y".equals(codeType)) {
                for (IndexDataDTO restData : fifteencity) {
                    restData.setCumulativeRatio("0");
                    restData.setCurrentValue("0");
                }
            }


            if ("J".equals(codeType)) {
                datetime = jiduTimeFormat(datetime);
            }
            quanGuoMap.put("datetime", datetime);
            // list.add(quansheng);
            int rank = 1;
            String flag1 = "1";
            String flag2 = "2";
            String flag3 = "3";

            for (IndexDataDTO city : fifteencity) {
                if (!"0".equals(city.getCurrentValue()) && ObjectUtils.isNotBlank(city.getCurrentValue())) {
                    flag1 = "0";
                }
                if (!"0".equals(city.getCumulativeValue()) && ObjectUtils.isNotBlank(city.getCumulativeValue())) {
                    flag2 = "0";
                }
                if (!"0".equals(city.getCumulativeRatio()) && ObjectUtils.isNotBlank(city.getCumulativeRatio())) {
                    flag3 = "0";
                }
            }
            StringBuffer showTab = new StringBuffer();

            //（年度）如果当前值有值，累计值没有值
            if ("0".equals(flag1) && "2".equals(flag2) && "N".equals(codeType)) {
                showTab.append("2");
                for (IndexDataDTO city : fifteencity) {

                    Map<String, Object> map = new HashMap<>();
                    String vV = "0";
                    String dV = "0";
                    String citycumValue = StringUtils.isBlank(city.getCumulativeValue()) ? "0" : city.getCumulativeValue();
                    String cityCurrentValue = StringUtils.isBlank(city.getCurrentValue()) ? "0" : city.getCurrentValue();
                    if (ObjectUtils.isNotBlank(city)) {
                        if (ObjectUtils.isNotBlank(city.getCumulativeValue())) {
                            // if ("亿元".equals(city.getUnit())) {
                            if ("万元".equals(resMap.get("unitname"))) {
                                vV = dataformatUnit(kexuejishu(citycumValue));
                                dV = dataformatUnit(kexuejishu(cityCurrentValue));
                                map.put("unit", "亿元");
                                unit = "亿元";
                            } else {
                                vV = dataFormat(kexuejishu(citycumValue));
                                dV = dataFormat(kexuejishu(cityCurrentValue));
                                map.put("unit", resMap.get("unitname"));
                                unit = resMap.get("unitname");
                            }

                        }
                    }
                    map.put("miniTitle", "");
                    if ("J".equals(codeType)) {
                        datetime = jiduTimeFormat(datetime);
                    }
                    map.put("datetime", datetime);
                    map.put("areaName", city.getAreaName());
                    map.put("areaCode", city.getAreaCode());
//                map.put("unit", resMap.get("unitname"));
                    map.put("currentValue", StringUtils.isBlank(dV) ? "0" : dV);
                    map.put("rank", StringUtils.isBlank(city.getRanks().toString()) ? "0" : city.getRanks());
                    map.put("cumulative", StringUtils.isBlank(dV) ? "0" : dV);
                    map.put("ratio", StringUtils.isBlank(city.getCumulativeRatio()) ? "0" : dataFormat1(city.getCumulativeRatio()));
                    rank++;
                    list.add(map);
                }
            } else {
                for (IndexDataDTO city : fifteencity) {

                    Map<String, Object> map = new HashMap<>();

                    String vV = "0";
                    String dV = "0";
                    String citycumValue = StringUtils.isBlank(city.getCumulativeValue()) ? "0" : city.getCumulativeValue();
                    String cityCurrentValue = StringUtils.isBlank(city.getCurrentValue()) ? "0" : city.getCurrentValue();
                    if (ObjectUtils.isNotBlank(city)) {
                        if (ObjectUtils.isNotBlank(city.getCumulativeValue())) {
                            // if ("亿元".equals(city.getUnit())) {
                            if ("万元".equals(resMap.get("unitname"))) {
                                vV = dataformatUnit(kexuejishu(citycumValue));
                                dV = dataformatUnit(kexuejishu(cityCurrentValue));
                                map.put("unit", "亿元");
                                unit = "亿元";
                            } else {
                                vV = dataFormat(kexuejishu(citycumValue));
                                dV = dataFormat(kexuejishu(cityCurrentValue));
                                map.put("unit", resMap.get("unitname"));
                                unit = resMap.get("unitname");
                            }

                            //九地市的规模以上工业产销率，页面上增长都改成累计
                            if (("A020201".equals(codeId) && "Y".equals(codeType))) {
                                vV = dataFormat(citycumValue);
                                dV = dataFormat(cityCurrentValue);
                                map.put("unit", "%");
                                unit = "%";
                            }

                        }
                    }
                    map.put("miniTitle", "");
                    if ("J".equals(codeType)) {
                        datetime = jiduTimeFormat(datetime);
                    }
                    map.put("datetime", datetime);
                    map.put("areaName", city.getAreaName());
                    map.put("areaCode", city.getAreaCode());
//                map.put("unit", resMap.get("unitname"));
                    map.put("currentValue", StringUtils.isBlank(dV) ? "0" : dV);
                    map.put("rank", StringUtils.isBlank(city.getRanks().toString()) ? "0" : city.getRanks());
                    map.put("cumulative", StringUtils.isBlank(vV) ? "0" : vV);
                    map.put("ratio", StringUtils.isBlank(city.getCumulativeRatio()) ? "0" : dataFormat1(city.getCumulativeRatio()));
                    rank++;
                    list.add(map);
                }
            }

//            if ("0".equals(flag1)) {
//                if (!("A020201".equals(codeId) && "Y".equals(codeType))) {
//                    showTab.append("1");
//                }
//            }
            if ("0".equals(flag2)) {
//                if (!("A020201".equals(codeId) && "Y".equals(codeType))) {
//                    showTab.append("2");
//                }
                showTab.append("2");
            }
            if ("0".equals(flag3)) {
                //九地市月度实际利用外资增长页面删除
                if (!("A050201".equals(codeId) && "Y".equals(codeType))) {
                    showTab.append("3");
                }

            }

            List<Map<String, Object>> list1 = new ArrayList<>();
            list1 = Until.deepCopy(list);
            //list1.addAll(list);
            Collections.sort(list1, new Comparator<Map<String, Object>>() {
                @Override
                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                    String val1 = (String) o1.get("currentValue");
                    Double valDouble1 = Double.parseDouble(val1);
                    String val2 = (String) o2.get("currentValue");
                    Double valDouble2 = Double.parseDouble(val2);
                    if (valDouble1 > valDouble2) {
                        return -1;
                    } else if (valDouble1 < valDouble2) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            });
            List<Map<String, Object>> list2 = new ArrayList<>();
            list2 = Until.deepCopy(list);
            //list2.addAll(list);
            Collections.sort(list2, new Comparator<Map<String, Object>>() {
                @Override
                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                    String val1 = (String) o1.get("cumulative");
                    Double valDouble1 = Double.parseDouble(val1);
                    String val2 = (String) o2.get("cumulative");
                    Double valDouble2 = Double.parseDouble(val2);
                    if (valDouble1 > valDouble2) {
                        return -1;
                    } else if (valDouble1 < valDouble2) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            });
            List<Map<String, Object>> list3 = new ArrayList<>();
            list3 = Until.deepCopy(list);
            // list3.addAll(list);
            Collections.sort(list3, new Comparator<Map<String, Object>>() {
                @Override
                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                    String val1 = (String) o1.get("ratio");
                    Double valDouble1 = Double.parseDouble(val1);
                    String val2 = (String) o2.get("ratio");
                    Double valDouble2 = Double.parseDouble(val2);
                    if (valDouble1 > valDouble2) {
                        return -1;
                    } else if (valDouble1 < valDouble2) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            });

            CopyOnWriteArrayList<Map<String, Object>> copy1 = new CopyOnWriteArrayList<>(list1);

            for (Map<String, Object> item : copy1) {
                //过滤---福州（不含平潭）
                if ("GX350126".equals(item.get("areaCode"))) {
                    copy1.remove(item);
                }
                //过滤---平潭
                if ("GX350128".equals(item.get("areaCode"))) {
                    copy1.remove(item);
                }
            }

            CopyOnWriteArrayList<Map<String, Object>> copy2 = new CopyOnWriteArrayList<>(list2);

            for (Map<String, Object> item : copy2) {
                //过滤---福州（不含平潭）
                if ("GX350126".equals(item.get("areaCode"))) {
                    copy2.remove(item);
                }
                //过滤---平潭
                if ("GX350128".equals(item.get("areaCode"))) {
                    copy2.remove(item);
                }
            }

            CopyOnWriteArrayList<Map<String, Object>> copy3 = new CopyOnWriteArrayList<>(list3);

            for (Map<String, Object> item : copy3) {
                //过滤---福州（不含平潭）
                if ("GX350126".equals(item.get("areaCode"))) {
                    copy3.remove(item);
                }
                //过滤---平潭
                if ("GX350128".equals(item.get("areaCode"))) {
                    copy3.remove(item);
                }
            }
            List<Map<String, Object>> s1 = restRank(nineRankAndColor(deepCopy(list1)), "1");
            List<Map<String, Object>> s2 = restRank(nineRankAndColor(deepCopy(list2)), "2");
            List<Map<String, Object>> s3 = restRank(nineRankAndColor(deepCopy(list3)), "3");

            //true 的话头部排名要留空
            boolean f1 = true;
            boolean f2 = true;
            boolean f3 = true;
            for (Map<String, Object> s : s1) {
                if (("0".equals(s.get("currentValue"))
                        || "0.0".equals(s.get("currentValue"))
                        || ObjectUtils.isBlank(s.get("currentValue")))
                        && (Integer) s.get("rank") == 2) {
                    f1 = false;
                } else {
                    f1 = true;
                }
                if ("3".equals(s.get("rank"))) {
                    f1 = true;
                }
            }
            for (Map<String, Object> s : s2) {
                if (("0".equals(s.get("cumulative"))
                        || "0.0".equals(s.get("cumulative"))
                        || ObjectUtils.isBlank(s.get("cumulative")))
                        && (Integer) s.get("rank") == 2) {
                    f2 = false;
                } else {
                    f2 = true;
                }
                if ("3".equals(s.get("rank"))) {
                    f2 = true;
                }
            }
            for (Map<String, Object> s : s3) {
                if (("0".equals(s.get("ratio"))
                        || "0.0".equals(s.get("ratio"))
                        || ObjectUtils.isBlank(s.get("ratio")))
                        && (Integer) s.get("rank") == 2) {
                    f3 = false;
                } else {
                    f3 = true;
                    break;
                }
                if ("3".equals(s.get("rank"))) {
                    f3 = true;
                    break;
                }
            }
            resultList.add(s1);
            resultList.add(s2);
            resultList.add(s3);
            quanGuoMap.put("list", resultList);

            if ("A050201".equals(codeId) && "N".equals(codeType)) {
                f1 = false;
                f2 = false;
                f3 = false;
            }
            quanGuoMap.put("f1", f1);
            quanGuoMap.put("f2", f2);
            quanGuoMap.put("f3", f3);
            quanGuoMap.put("showTab", showTab);
            //九地市在原本全市数据上要加一个全省数据
            Map<String, String> provinceData = new HashMap<>();


            List<IndexDataDTO> data = dataService.queryListIndexDate(codeId, StringUtils.isNotBlank(datetime) ? datetime.substring(0, 4) : null, "GX350200", codeType, "P");
            for (IndexDataDTO datum : data) {
                //如果是季度
                if ("J".equals(codeType)) {
                    String timeFlag = "A";
                    switch (datetime.substring(4, 6)) {
                        case "03":
                            timeFlag = "A";
                            break;
                        case "06":
                            timeFlag = "B";
                            break;
                        case "09":
                            timeFlag = "C";
                            break;
                        case "12":
                            timeFlag = "D";
                            break;
                        default:
                            timeFlag = "A";
                            break;
                    }
                    if (datum.getDatetime().contains(timeFlag)) {
                        provinceData.put("cumulative", dataFormat2(kexuejishu(datum.getCumulativeValue())));
                        provinceData.put("ratio", dataFormat2(kexuejishu(datum.getCumulativeRatio())));
                        provinceData.put("title", "全省数据");
                        provinceData.put("currentValue", dataFormat2(kexuejishu(datum.getCurrentValue())));
                        provinceData.put("datetime", datum.getDatetime().substring(0, 4) + timeFlag);
                        provinceData.put("unit", unit);
                    }
                } else if ("N".equals(codeType)) {
                    provinceData.put("cumulative", dataFormat2(kexuejishu(datum.getCumulativeValue())));
                    provinceData.put("ratio", dataFormat2(kexuejishu(datum.getCumulativeRatio())));
                    provinceData.put("title", "全省数据");
                    provinceData.put("currentValue", dataFormat2(kexuejishu(datum.getCurrentValue())));
                    provinceData.put("datetime", datum.getDatetime());
                    provinceData.put("unit", unit);
                } else {
                    provinceData.put("cumulative", dataFormat2(kexuejishu(datum.getCumulativeValue())));
                    provinceData.put("ratio", dataFormat2(kexuejishu(datum.getCumulativeRatio())));
                    provinceData.put("title", "全省数据");
                    provinceData.put("currentValue", dataFormat2(kexuejishu(datum.getCurrentValue())));
                    provinceData.put("datetime", datum.getDatetime());
                    provinceData.put("unit", unit);
                }
            }
            quanGuoMap.put("province", provinceData);
        }
        return quanGuoMap;
    }


    public String jiduTimeFormat(String datetime) {
        String flag = datetime.substring(4, 5);
        switch (flag) {
            case "A":
                datetime = datetime.substring(0, 4) + "03";
                break;
            case "B":
                datetime = datetime.substring(0, 4) + "06";
                break;
            case "C":
                datetime = datetime.substring(0, 4) + "09";
                break;
            case "D":
                datetime = datetime.substring(0, 4) + "12";
                break;
        }
        return datetime;
    }

    public String timeToJiduFormat(String datetime) {
        if (datetime.length() == 5) {
            return datetime;
        }
        String flag = datetime.substring(4, 6);
        switch (flag) {
            case "03":
                datetime = datetime.substring(0, 4) + "A";
                break;
            case "06":
                datetime = datetime.substring(0, 4) + "B";
                break;
            case "09":
                datetime = datetime.substring(0, 4) + "C";
                break;
            case "12":
                datetime = datetime.substring(0, 4) + "D";
                break;
        }
        return datetime;
    }

    //四个经济特区排序与颜色
    public List<Map<String, Object>> fourRankAndColor(List<Map<String, Object>> list) {
        for (int i = 0; i < list.size(); i++) {
            if (i == 0) {
                list.get(i).put("miniTitle", "各经济特区排名");
            } else {
                list.get(i).put("miniTitle", "");
            }
            if (i < 2) {
                list.get(i).put("color", "blue");
            } else if (i > 1 && i < 4) {
                list.get(i).put("color", "orange");
            } else if (i > 3) {
                list.get(i).put("color", "red");
            }
        }
        return list;
    }

    //九地市排序与颜色
    public List<Map<String, Object>> nineRankAndColor(List<Map<String, Object>> list) {
        for (int i = 0; i < list.size(); i++) {
            if (i == 0) {
                list.get(i).put("miniTitle", "各市排名");
            } else {
                list.get(i).put("miniTitle", "");
            }
            if (i < 3) {
                list.get(i).put("color", "blue");
            } else if (i >= 3 && i < 6) {
                list.get(i).put("color", "orange");
            } else if (i > 5) {
                list.get(i).put("color", "red");
            }
        }
        return list;
    }

    //区级排序与颜色
    public List<Map<String, Object>> qujiRankAndColor(List<Map<String, Object>> list) {
        for (int i = 0; i < list.size(); i++) {
            if (i == 0) {
                list.get(i).put("miniTitle", "各区排名");
            } else {
                list.get(i).put("miniTitle", "");
            }
            if (i < 2) {
                list.get(i).put("color", "blue");
            } else if (i > 1 && i < 4) {
                list.get(i).put("color", "orange");
            } else if (i > 3) {
                list.get(i).put("color", "red");
            }
        }
        return list;
    }


    //十五个副省级排序与颜色
    public List<Map<String, Object>> fifteenRankAndColor(List<Map<String, Object>> list) {
        for (int i = 0; i < list.size(); i++) {
            if (i % 5 == 0) {
                if (i < 5) {
                    list.get(i).put("miniTitle", "排名前5个城市");
                }
                if (i == 5) {
                    list.get(i).put("miniTitle", "排名中间5个城市");
                }
                if (i > 5) {
                    list.get(i).put("miniTitle", "排名末5个城市");
                }
            } else {
                list.get(i).put("miniTitle", "");
            }
            if (i < 5) {
                list.get(i).put("color", "blue");
            } else if (i > 4 && i < 10) {
                list.get(i).put("color", "orange");
            } else if (i > 9) {
                list.get(i).put("color", "red");
            }
        }
        return list;
    }


    public List<IndexDataDTO> quanshiData(String codeId, String codeType, String areaType, String datetime) {
        //单独处理 全市数据：
        List<OneIndex> index = oneservice.getNameById(codeId, codeType, areaType, null);
        List<IndexDataDTO> xiamenCitys = new ArrayList<>();
        //社会消费品零售总额
        if ("A0205".equals(codeId)) {
            return xiamenCitys = dataService.queryListIndexDate("A0E010101",
                    datetime, "GX350200", codeType, "D", index.get(0).getCodeName());
        }
        //固定资产投资
        if ("A0206".equals(codeId)) {
            return xiamenCitys = dataService.queryListIndexDate("A050201",
                    datetime, "GX350200", codeType, "D", index.get(0).getCodeName());
        }

        if (index.size() > 0) {
            xiamenCitys = dataService.queryListIndexDate(null,
                    datetime, "GX350200", codeType, "D", index.get(0).getCodeName());
            if (xiamenCitys.size() == 0) {
                return dataService.queryListIndexDate(null,
                        datetime, "GX350200", codeType, "E", index.get(0).getCodeName());
            }

        }
        return xiamenCitys;
    }


    public List<Map<String, Object>> restRank(List<Map<String, Object>> def, String flag) {
        List<Map<String, Object>> abc = deepCopy(def);
        int rank = 1;
        switch (flag) {
            case "1":
                for (int i = 0; i < abc.size(); i++) {
                    if (i == 0) {
                        abc.get(i).put("rank", rank);
                        rank++;
                    } else {
                        double currentValue = Double.parseDouble(ObjectUtils.isBlank(abc.get(i).get("currentValue")) ? "0.0" : (String) abc.get(i).get("currentValue"));
                        double preCurrentValue = Double.parseDouble(ObjectUtils.isBlank(abc.get(i - 1).get("currentValue")) ? "0.0" : (String) abc.get(i - 1).get("currentValue"));
                        if (currentValue == preCurrentValue) {
                            abc.get(i).put("rank", abc.get(i - 1).get("rank"));
                            rank++;
                        } else {
                            abc.get(i).put("rank", rank);
                            rank++;
                        }
                    }
                }
                break;
            case "2":
                for (int i = 0; i < abc.size(); i++) {
                    if (i == 0) {
                        abc.get(i).put("rank", rank);
                        rank++;
                    } else {
                        double currentValue = Double.parseDouble(ObjectUtils.isBlank(abc.get(i).get("cumulative")) ? "0.0" : (String) abc.get(i).get("cumulative"));
                        double preCurrentValue = Double.parseDouble(ObjectUtils.isBlank(abc.get(i - 1).get("cumulative")) ? "0.0" : (String) abc.get(i - 1).get("cumulative"));
                        if (currentValue == preCurrentValue) {
                            abc.get(i).put("rank", abc.get(i - 1).get("rank"));
                            rank++;
                        } else {
                            abc.get(i).put("rank", rank);
                            rank++;
                        }
                    }
                }
                break;
            case "3":
                for (int i = 0; i < abc.size(); i++) {
                    if (i == 0) {
                        abc.get(i).put("rank", rank);
                        rank++;
                    } else {
                        double currentValue = Double.parseDouble(ObjectUtils.isBlank(abc.get(i).get("ratio")) ? "0.0" : (String) abc.get(i).get("ratio"));
                        double preCurrentValue = Double.parseDouble(ObjectUtils.isBlank(abc.get(i - 1).get("ratio")) ? "0.0" : (String) abc.get(i - 1).get("ratio"));
                        if (currentValue == preCurrentValue) {
                            abc.get(i).put("rank", abc.get(i - 1).get("rank"));
                            rank++;
                        } else {
                            abc.get(i).put("rank", rank);
                            rank++;
                        }
                    }
                }
                break;
        }
        return abc;
    }
}
